
#ifndef	__UR_IMPLEMENT_H
#define	__UR_IMPLEMENT_H
typedef enum{
	UR_SEND_CMD_NONE,
	UR_SEND_CMD_KEY,
    UR_SEND_CMD_SWIP_CARD,
	UR_SEND_CMD_RECHAGRE_FEEDBACK,
	UR_SEND_CMD_CONSUME_FEEDBACK,
	UR_SEND_CMD_SET_BANLANCE_FEEDBACK,
	UR_SEND_CMD_MONEY,
	UR_SEND_CMD_VERSION,
	UR_SEND_CMD_SET_CONSUME_MODE,
	UR_SEND_CMD_REQUEST_MODE,
	UR_SEND_CMD_SET_BALANCE_SPE,	
}UR_SEND_CMD_E;

typedef enum{
	UR_SEND_CMD_2_NONE,
	UR_SEND_CMD_2_CONSUME_FEEDBACK,
	UR_SEND_CMD_2_RECHANGE_FEEDBACK,
	UR_SEND_CMD_2_SET_BANLANCE_FEEDBACK,
	UR_SEND_CMD_2_WAIT_CARD_OVER_TIME,
	UR_SEND_CMD_2_ENABLE_USE, 
	UR_SEND_CMD_2_VERSION,
	UR_SEND_CMD_2_REQUEST_MODE,
	//UR_SEND_CMD_2_FAILED_ALARM,
	UR_SEND_CMD_2_ILLEGAL_CARD_ALARM,
}UR_SEND_CMD_2_E;



typedef enum{
	UR_SEND_STATUS_IDLE,
	UR_SEND_STATUS_SENDED_AND_WAIT_OK
}UR_SEND_STATUS_E;

typedef enum{
	EDIT_AUTH_CARD_ADD,
	EDIT_AUTH_CARD_DEL
}EDIT_AUTH_CARD_TYPE_E;

#define CARD_SRN_LEN 8

#define UR_SEND_PARA_LEN 25

#define UR_SEND_BUFFER_LEN 30

#define UR_SEND_BUF_OK_LEN 6

#define UR_SEND_RETRY_TIME 20

#define AUTH_SEND_INTERVAL_TIME_CON 10

#define STOP_TIMER 0xFF

#define UR_SEND_INTERVAL_TIME_CON 1

#define UR_SEND_INTERVAL_TIME_CON_2 1





#define UR_CMD_LEN 						1
#define UR_PARA_LEN_ILLEGAL_CARD_ALARM	1
#define UR_PARA_LEN_REQUEST_MODE		1
#define UR_PARA_LEN_CARD_NUMBER 		10
#define UR_PARA_LEN_BALANCE				5
#define UR_PARA_LEN_RECHANGE_AUTH_CODE 	8
#define UR_PARA_LEN_TOTAL_SWIP_CARD		(UR_PARA_LEN_CARD_NUMBER+UR_PARA_LEN_BALANCE+UR_PARA_LEN_RECHANGE_AUTH_CODE)
#define UR_CS_LEN_SWIP_CARD (UR_CMD_LEN+UR_PARA_LEN_TOTAL_SWIP_CARD)


#define UR_PARA_RECHANGE_STATUS 1
#define UR_PARA_CONSUME_STATUS UR_PARA_RECHANGE_STATUS
#define UR_PARA_LEN_TOTAL_RECHANGE_FEEDBACK (UR_PARA_RECHANGE_STATUS)
#define UR_CS_LEN_RECHANGE_FEEDBACK (UR_CMD_LEN+UR_PARA_LEN_TOTAL_RECHANGE_FEEDBACK)
#define UR_PARA_LEN_TOTAL_CONSUME_FEEDBACK (UR_PARA_CONSUME_STATUS+UR_PARA_LEN_BALANCE)
#define UR_CS_LEN_CONSUME_FEEDBACK  (UR_CMD_LEN+UR_PARA_LEN_TOTAL_CONSUME_FEEDBACK)


#define UR_PARA_LEN_TOTAL_RECHANGE_FEEDBACK_TO_KEYBOARD (UR_PARA_RECHANGE_STATUS+UR_PARA_LEN_BALANCE)

#define UR_CS_LEN_RECHANGE_FEEDBACK_TO_KEYBOARD (UR_CMD_LEN+UR_PARA_LEN_TOTAL_RECHANGE_FEEDBACK_TO_KEYBOARD)


#define UR_PARA_LEN_TOTAL_CONSUME_FEEDBACK_TO_MTK (UR_PARA_CONSUME_STATUS)

#define UR_CMD_REQUEST_VERSION 'Q'


#define UR_CMD_RECHANGE		'R'
#define UR_PARA_LEN_RECHANGE_VALUE  UR_PARA_LEN_BALANCE
#define UR_CS_LEN_RECHANGE  (UR_CMD_LEN+UR_PARA_LEN_BALANCE+UR_PARA_LEN_RECHANGE_AUTH_CODE)


#if ENABLE_CS_CONSUME
#define UR_PARA_LEN_CONSUME_AUTH_CODE 	8

#define UR_CMD_CONSUME		'S'
#define UR_PARA_LEN_CONSUME_VALUE  UR_PARA_LEN_BALANCE
#define UR_CS_LEN_CONSUME  (UR_CMD_LEN+UR_PARA_LEN_BALANCE+UR_PARA_LEN_CONSUME_AUTH_CODE)
#else
#define UR_CMD_CONSUME		'S'
#define UR_PARA_LEN_CONSUME_VALUE  UR_PARA_LEN_BALANCE
#define UR_CS_LEN_CONSUME  (UR_CMD_LEN+UR_PARA_LEN_BALANCE)
#endif


#define UR_CMD_SET_BANLANCE 'T'
#define UR_PARA_LEN_SET_BANLANCE_VALUE UR_PARA_LEN_BALANCE
#define UR_CS_LEN_SET_BANLANCE (UR_CMD_LEN+UR_PARA_LEN_BALANCE)
#define UR_PARA_SET_BANLANCE_STATUS 1
#define UR_PARA_LEN_TOTAL_SET_BANLANCE_FEEDBACK_TO_MTK UR_PARA_SET_BANLANCE_STATUS


#define UR_PARA_LEN_TOTAL_SET_BANLANCE_FEEDBACK_TO_KEYBOARD (UR_PARA_SET_BANLANCE_STATUS+UR_PARA_LEN_BALANCE)


#define UR_CMD_ENABLE_USE  'U'
#define UR_PARA_LEN_ENABLE_STATUS 1
#define UR_CS_LEN_ENABLE_USE (UR_CMD_LEN+UR_PARA_LEN_ENABLE_STATUS)



#define UR_CMD_SET_SERVICE_BANLANCE 'W'
#define UR_PARA_LEN_SET_SERVICE_BANLANCE_VALUE UR_PARA_LEN_BALANCE
#define UR_CS_LEN_SET_SERVICE_BANLANCE (UR_CMD_LEN+UR_PARA_LEN_SET_SERVICE_BANLANCE_VALUE+UR_PARA_LEN_RECHANGE_AUTH_CODE)
#define UR_PARA_SET_BANLANCE_STATUS 1
#define UR_PARA_LEN_TOTAL_SET_BANLANCE_FEEDBACK_TO_MTK UR_PARA_SET_BANLANCE_STATUS

#define UR_PARA_LEN_TOTAL_SET_BANLANCE_FEEDBACK_TO_KEYBOARD (UR_PARA_SET_BANLANCE_STATUS+UR_PARA_LEN_BALANCE)


#define UR_CMD_REQUEST_MODE		'P'
#define UR_PARA_LEN_REQUEST_MODE_VALUE  UR_PARA_LEN_REQUEST_MODE
#define UR_CS_LEN_REQUEST_MODE  (UR_CMD_LEN+UR_PARA_LEN_REQUEST_MODE)


#define UR_CMD_WAIT_CARD_OVER_TIME 'V'
#define UR_CS_LEN_WAIT_CARD_OVER_TIME (UR_CMD_LEN)



#define UR_CMD_CONSUME_SPEC		'X'
#define UR_PARA_LEN_CONSUME_SPEC_VALUE  UR_PARA_LEN_BALANCE
#define UR_CS_LEN_CONSUME_SPEC  (UR_CMD_LEN+UR_PARA_LEN_CONSUME_SPEC_VALUE+UR_PARA_LEN_RECHANGE_AUTH_CODE)


#define UR_CMD_START_BOOT 'J'
#define UR_PARA_SET_START_BOOT_STATUS 1

#define UR_CMD_ILLEGAL_CARD_ALARM		'A'
#define UR_PARA_LEN_ILLEGAL_CARD_ALARM_VALUE  UR_PARA_LEN_ILLEGAL_CARD_ALARM
#define UR_CS_LEN_ILLEGAL_CARD_ALARM  (UR_CMD_LEN+UR_PARA_LEN_ILLEGAL_CARD_ALARM)

#define UR_CMD_SET_BALANCE_SPE		'i'
#define UR_PARA_LEN_BALANCE_SPE		1
#define UR_CS_SET_BALANCE_SPE  		(UR_CMD_LEN+UR_PARA_LEN_BALANCE_SPE)
#define UR_CMD_READ_BALANCE_SPE		'r'


#define UR_CMD_LCD_VIEW_NET_STATUS		'w'
//#define UR_CMD_LCD_VIEW_SCHOOL_INFO		's'

#define UR_CMD_LCD_VIEW_TIME_INFO			't'
#define UR_PARA_LEN_LCD_VIEW_TIME_INFO 		16
#define UR_CS_LCD_VIEW_TIME_INFO		 		(UR_CMD_LEN + UR_PARA_LEN_LCD_VIEW_TIME_INFO)

#define UR_CMD_LCD_VIEW_STUDENT_INFO		'n'
#define UR_CMD_LCD_VIEW_CHECK_INFO				'h'

#define UR_CMD_DEBUG				'd'

#define UR_HEAD_CS_TAIL_LEN 			6

extern u8 ur_send_timer;

extern u8 ur_send_timer_2;

extern u8 enable_use;


extern void ur_implement_init(void);

extern void ur_implement_loop(void);

extern void ur_implement_send_task(void);

extern void ur_send_cmd(UR_SEND_CMD_E cmd,u8 *para,u8 para_len);

extern void ur_send_cmd_2(UR_SEND_CMD_2_E cmd,u8 *para,u8 para_len);

extern void ur_implement_timer(void);

extern UR_SEND_STATUS_E ur_get_send_status(void);

extern void ur_set_send_status(UR_SEND_STATUS_E st);

extern void ur_implement_send_ok(void);

extern void ur_calculate_checksum(u8 *cs,u8 *src,u8 src_len);

extern u8 ur_checksum_if_is_ok(u8 *frm,u8 len);

extern void ur_implement_send_ok_2(void);

extern void ur_implement_send_task_2(void);

extern UR_SEND_STATUS_E ur_get_send_status_2(void);

extern void ur_set_send_status_2(UR_SEND_STATUS_E st);

extern void ur_implement_send(void);

extern void ur_implement_send_2(void);

//extern u8 card_if_is_auth_card(u8 *snr);

#endif

